package st.business.tepth.business.taskallocation.returnfactory;

import st.business.tepth.base.OnDataConvertListener;
import st.business.tepth.business.bean.ReturnFactoryBean;

/**
 * Author: shadow
 * Email:  1025431817@qq.com
 * Time:   2019-09-02 18:13
 */

public class ReturnFactoryPresenter extends ReturnFactoryContract.Presenter {
    private final ReturnFactoryContract.View mView;
    private final ReturnFactoryContract.Model mModel;

    public ReturnFactoryPresenter(ReturnFactoryContract.View view) {
        mView = view;
        mModel = new ReturnFactoryModel();
    }

    @Override
    void getData(String token, int repairId) {
        addDisposable(mModel.getData(token, repairId,
                new OnDataConvertListener<ReturnFactoryBean>() {
                    @Override
                    public void convert(ReturnFactoryBean s) {
                        if (mView != null) {
                            mView.showData(s);
                        }
                    }

                    @Override
                    public void error(int code, String msg) {
                        if (mView != null) {
                            mView.showData(null);
                        }
                    }
                }));
    }

    @Override
    void returnFactory(String token, int repairId, String phenomenonIds,
                       String maintenanceIds, int rescueFlag) {
        addDisposable(mModel.returnFactory(token, repairId, phenomenonIds,
                maintenanceIds, rescueFlag,
                new OnDataConvertListener<String>() {
                    @Override
                    public void convert(String s) {
                        if (mView != null) {
                            mView.returnSucceed();
                        }
                    }

                    @Override
                    public void error(int code, String msg) {
                        if (mView != null) {
                            mView.showError(msg);
                        }
                    }
                }));
    }
}
